//
//  ChooseClassifyCtr.m
//  Four_years
//
//  Created by 中软国际088 on 15/11/11.
//  Copyright © 2015年 中软三班四年小组. All rights reserved.
//

#import "ChooseClassifyCtr.h"
#import "SingleClassifyValue.h"
@interface ChooseClassifyCtr ()
@property NSMutableArray *classifyArray;
@end

@implementation ChooseClassifyCtr

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self initClassify];

    
    [self initTable];
        
    
  }

//初始化分类
- (void)initClassify{

    NSString *path = [self getPlistPath];
    
    _classifyArray = [NSMutableArray arrayWithContentsOfFile:path];
    
    
    


}

//初始化选择表格
- (void)initTable{

    UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)style:UITableViewStyleGrouped];
    
    table.dataSource = self;
    
    table.delegate = self;
    
    [self.view addSubview:table];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _classifyArray.count;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *name = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:name];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:name];
        
        NSDictionary * dic = _classifyArray[indexPath.row];
        cell.textLabel.text = [dic valueForKey:@"name"];
        cell.imageView.image = [UIImage imageNamed:[dic valueForKey:@"image"]];
        
    }

    return cell;
    
}


- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    

}

//读取plist文件路径
- (NSString *)getPlistPath{

NSString *path = [[NSBundle mainBundle] pathForResource:@"DirayClassify List" ofType:@"plist"];
    
    
    
    return path;
    
}

//cell点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

   
    NSDictionary * dic = _classifyArray[indexPath.row];
    NSString *name = [dic valueForKey:@"name"];
    
    SingleClassifyValue * passName =  [SingleClassifyValue shareManager];
    
    passName.classfiyName = name;
    
    [self.navigationController popToRootViewControllerAnimated:YES];
    

}

@end
